<template>
  <page-layout>
    <div slot="toolbar">
      <el-button size="small" round @click="goBack">返回</el-button>
    </div>
    <div class="card-header m_10">评论管理</div>

    <el-card class="box-card m_10">
      <el-card class="box-card">
        <el-row>
          <el-col :span="24">
            <el-form ref="searchCondition" :model="searchCondition" label-width="80px" inline>
              <el-form-item label="评论内容">
                <el-input v-model="searchCondition.comment" style="width: 400px;"/>
              </el-form-item>
              <el-form-item>
                <el-button type="primary" @click="refresh(1)">查询</el-button>
              </el-form-item>
            </el-form>
          </el-col>
        </el-row>
      </el-card>
            <el-table
              :data="discusss.content" border stripe
              style="width: 100%">
              <el-table-column
                prop="id"
                label="编号"
                width="110">
              </el-table-column>
              <el-table-column prop="newsTitle" label="新闻标题" ></el-table-column>
              <el-table-column prop="usName" label="评论人姓名" width="120"></el-table-column>
              <el-table-column prop="comment" label="评论内容" ></el-table-column>
              <el-table-column prop="createTime" label="评论时间" width="160"></el-table-column>
              <el-table-column label="操作" width="180">
                <template slot-scope="scope">
                  <el-button size="mini" type="text" @click="handleDelete(scope.row)">删除</el-button>
                </template>
              </el-table-column>
            </el-table>
            <div class="mt10">
              <el-pagination
                background
                layout="prev, pager, next"
                :total="discusss.totalElements"
                :page-size="discusss.size"
                :current-page.sync="currentAdminPage" @current-change="adminPageChange">
              </el-pagination>
            </div>
    </el-card>
  </page-layout>
</template>
<script>
import { mapGetters } from "vuex";
import PageLayout from "@/components/page-layout";
export default {
  beforeRouteEnter(to, from, next) {
    next(vm => {
      vm.newsId = to.query.newsId;
      vm.refresh();
    });
  },
  created() {},
  mounted() {},
  data() {
    return {
      currentAdminPage: 1,
      newsId: "",
      searchCondition: { comment: "", pageSize: 10 }
    };
  },
  computed: {
    ...mapGetters({
      discusss: "discusss"
    })
  },
  methods: {
    createCode(text) {},
    goBack() {
      this.$router.push({ name: "news" });
    },
    adminPageChange(val) {
      this.$store
        .dispatch(
          "getDiscussPageS",
          Object.assign(this.searchCondition, {
            pageIndex: val - 1,
            newsId: this.newsId
          })
        )
        .then(ret => {});
    },

    handleDelete(row) {
      this.$confirm("确认删除该评论吗?", "提示", {})
        .then(() => {
          this.$store.dispatch("deleteDiscussS", { id: row.id }).then(ret => {
            this.refresh({ pageIndex: 0 });
            this.$notify({
              title: "删除成功",
              type: "success"
            });
          });
        })
        .catch(() => {});
    },
    refresh() {
      this.adminPageChange(1);
    }
  },
  components: { PageLayout }
};
</script>
<style lang="less">
.m_10 {
  margin: 10px;
}
.m_t_10 {
  margin-top: 10px;
}
.tree_edit {
  float: right;
}
.line {
  border: 0.5px solid #ebeef5;
  margin-top: 20px;
  margin-bottom: 10px;
}
</style>
